package paper.cluster;

import paper.graph.Edge;

/* This is a customised Edge with the measure for the clustering
   algorithm. The baseclass is in paper.graph
*/

// NOT currently implementing makeDefault and yet the fillGraph
// code works anyway.... ?
public class CEdge extends Edge
{
    public CEdge(String a, String b)
    {
        super(a,b);
        m = new Measure();
    }

    class Measure implements Comparable<Measure>
    {
        public int length,number;
        public Measure()
        {
            number = 1;
            length =-1;
        }

        public String toString()
        {
            //return keyA + "->" + keyB + "=" + number;
            if( number==1 )
                return  "label=\"" + length + "\"";
            return "label=\"" + number + "x" + length + "\"";
        }

        public int compareTo(Measure o)
        {
            if( length==-1 && o.length==-1)
                return 0;
            if( length==-1 && o.length!=-1)
                return 1;
            if( length!=-1 && o.length==-1)
                return -1;
            if( length==o.length )
            {
                if( number>o.number )
                    return -1;
                if( number==o.number )
                    return 0;
                return 1;
            }
            if( length<o.length )
                return -1;
            return 1;
        }
    }
    Measure m;

    public String toString()
    {
        String colStr;
        colStr = "color=\"" + colString() + "\",";
        return "[" + colStr + m.toString() + "]";
    }

    String colDigs(int comp)
    {
        String rawDigs = Integer.toHexString( comp );
        if( rawDigs.length() == 1 )
            return "0" + rawDigs;
        return rawDigs;
    }

    String colString()
    {
        return "#" + 
               colDigs( col.getRed() ) +
               colDigs( col.getGreen() ) +
               colDigs( col.getBlue() );
    }

    public CEdge makeDefault(String a, String b)
    {
        //System.out.println("CEdge::makeDefault " + a + "," + b);
        return new CEdge(a,b);
    }
    public CEdge copy()
    {
        CEdge y = new CEdge(keyA,keyB);
        y.col = col;
        y.m = m;
        return y;
    }
}
